package com.junke.question.service.filter;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.junke.question.service.entity.SysUser;
import com.junke.question.service.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
    @Autowired
    private ISysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser user = sysUserService.getOne(new QueryWrapper<SysUser>().eq("user_name", username));
        if(user == null){
            throw new UsernameNotFoundException("user not found!!");
        }
        return new JwtAuthUser(user);

    }
}
